/**  
* @Title: SansuiZuulFilter.java 
* @Description:
* @Copyright: Copyright (c) 2018
* @Company:http://www.sinocon.cn
* @author Administrator  
* @date 2018年4月21日  
* @version 1.0  
*/
package com.sansui.zull.config;

import javax.servlet.http.HttpServletRequest;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

/**
 * @Title: SansuiZuulFilter
 * @Description:
 * @author:Administrator
 * @date 2018年4月21日
 */
public class SansuiZuulFilter extends ZuulFilter {

	/*
	 * (non-Javadoc)
	 * 
	 * <p>Title: run</p>
	 * 
	 * <p>Description: </p>
	 * 
	 * @return
	 * 
	 * @see com.netflix.zuul.IZuulFilter#run()
	 * 
	 */
	@Override
	public Object run() {
		RequestContext ctx = RequestContext.getCurrentContext();
		HttpServletRequest request = ctx.getRequest();
		Object accessToken = request.getParameter("shiroSessionId");
		if (accessToken == null) {
			ctx.setSendZuulResponse(false);
			ctx.setResponseStatusCode(401);
			try {
				ctx.getResponse().getWriter().write("token is empty");
			} catch (Exception e) {
			}

			return null;
		}
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * <p>Title: shouldFilter</p>
	 * 
	 * <p>Description: </p>
	 * 
	 * @return
	 * 
	 * @see com.netflix.zuul.IZuulFilter#shouldFilter()
	 * 
	 */
	@Override
	public boolean shouldFilter() {
		// TODO Auto-generated method stub
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * <p>Title: filterOrder</p>
	 * 
	 * <p>Description: </p>
	 * 
	 * @return
	 * 
	 * @see com.netflix.zuul.ZuulFilter#filterOrder()
	 * 
	 */
	@Override
	public int filterOrder() {
		// TODO Auto-generated method stub
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * <p>Title: filterType</p>
	 * 
	 * <p>Description: </p>
	 * 
	 * @return
	 * 
	 * @see com.netflix.zuul.ZuulFilter#filterType()
	 * 
	 */
	@Override
	public String filterType() {
		// TODO Auto-generated method stub
		return "pre";
	}

}
